import { defineConfig } from "vite";
import uni from "@dcloudio/vite-plugin-uni";
import vueJsx from "@vitejs/plugin-vue-jsx";
import { resolve } from "path";
import Components from "unplugin-vue-components/vite";
import AutoImport from "unplugin-auto-import/vite";
import AutoExportImg from "./src/plugins/vite-plugin-auto-export-img";
export default defineConfig({
  define: {
    __VUE_I18N_FULL_INSTALL__: true,
    __VUE_I18N_LEGACY_API__: true,
    __VUE_I18N_PROD_DEVTOOLS__: false,
  },
  build: {
    target: "es6",
  },
  css: {
    preprocessorOptions: {
      scss: {
        api: "modern-compiler",
        silenceDeprecations: ["legacy-js-api"],
      },
    },
  },
  resolve: {
    alias: {
      "@": resolve(__dirname, "src"),
      "@types": resolve(__dirname, "types"),
    },
    // alias: [
    //   {
    //     find: "@",
    //     replacement: resolve(__dirname, "src"),
    //   },
    // ],
  },
  server: {
    port: 1314,
    // 选项写法
    proxy: {
      "/pag": {
        target: "https://cdn.tmui.design",
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api/, "/api"),
      },
    },
  },
  plugins: [
    uni(),
    vueJsx(),
    AutoImport({
      include: [
        /\.[tj]sx?$/, // .ts, .tsx, .js, .jsx
        /\.vue$/,
        /\.vue\?vue/, // .vue
      ],
      imports: ["vue", "uni-app", "pinia"],
      dts: "types/auto-imports.d.ts",
      eslintrc: {
        enabled: true,
      },
    }),
    AutoExportImg(),
    Components({
      dts: true,
      resolvers: [
        // example of importing Vant
        (componentName) => {
          if (componentName.startsWith("tm")) {
            return { name: componentName.slice(2), from: "tm" };
          }
        },
      ],
      dirs: ["./src/uni_modules/tm-ui/components"],
      include: [/\.vue$/, /\.uvue$/],
    }),
  ],
});
